import threading
from queue import Queue


class AbstractLink(threading.Thread):
    def __init__(self):
        super().__init__()
        self.__parameters = {}
        self.__parameters_lock = threading.Lock()
        self.__invoke_terminal = False
        self.__invoke_terminal_lock = threading.Lock()
        self.input_queue = Queue()
        self.output_queue = Queue()

    @staticmethod
    def data_to_hex_string(data: bytes) -> str:
        return "".join(f"{byte:02x}" for byte in data)

    def save(self):
        self.__parameters_lock.acquire()
        tmp = self.__parameters
        self.__parameters_lock.release()
        return tmp

    def load(self, parameters):
        self.__parameters_lock.acquire()
        self.__parameters = parameters
        self.__parameters_lock.release()

    def invoke_terminal(self):
        self.__invoke_terminal_lock.acquire()
        tmp = self.__invoke_terminal
        self.__invoke_terminal_lock.release()
        return tmp

    def set_invoke_terminal(self, invoke_terminal):
        self.__invoke_terminal_lock.acquire()
        self.__invoke_terminal = invoke_terminal
        self.__invoke_terminal_lock.release()
